package cease.command.photo;

import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.Option;

import cease.butter.PhotoExecutor;
import cease.command.HasOptionCommand;
import cease.console.PrintHelper;
import cease.urs.Session;
import cease.vo.UploadedPhoto;

public class PhotoUploadCommand extends HasOptionCommand {

    @Option(name = "-f", metaVar = "required", required = true, usage = "image file path")
    private String filePath;

    @Option(name = "-m", metaVar = "optional", usage = "add water mark text in image")
    private String watermark;

    public String getCmdDesc() {
        return "upload a photo";
    }

    private void reset() {
        filePath = null;
        watermark = null;
    }

    public void run(Session session, String[] args) throws Exception {
        try {
            parser.parseArgument(args);
            UploadedPhoto up = PhotoExecutor.getInstance().upload(session,
                    filePath, watermark, null, null, null, null, null, null);
            PrintHelper.printUploadedPhoto(up);
        } catch (CmdLineException e) {
            parser.printUsage(System.out);
        } finally {
            reset();
        }
    }
}
